﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace PowerAwareBluetooth.Controller.AI
{
    [Serializable]
    /// <summary>
    /// a single state machine
    /// </summary>
    public class StateMachine
    {
        private States m_currentState;

        private const States MAX_STATE = States.ON_HARD;
        private const States MIN_STATE = States.OFF_HARD;

        /// <summary>
        /// represents State in the learning state machine
        /// </summary>
        public enum States
        {
            OFF_HARD = -2,
            OFF = -1,
            ON = 0,
            ON_HARD = 1
        }

        /// <summary>
        /// C'tor
        /// </summary>
        public StateMachine()
        {
            //default state is ON
            m_currentState = States.ON;
        }

        /// <summary>
        /// Increment the State (for example move from ON to ON_HARD)
        /// </summary>
        public void IncrementState()
        {
            if (m_currentState < MAX_STATE)
            {
                m_currentState++;
            }
        }

        /// <summary>
        /// Decrement the state (for example move from ON_HARD to ON)
        /// </summary>
        public void DecrementState()
        {
            if (m_currentState > MIN_STATE)
            {
                m_currentState--;
            }
        }

        /// <summary>
        /// return the current state of the state machine
        /// </summary>
        public States CurrentState
        {
            get
            {
                return m_currentState;
            }
        }

        internal void Reset()
        {
            m_currentState = States.ON;
        }
    }
}
